if [ $1 == 'prepare' ];then
	yum -y install gcc gcc-c++ mysql-libs mysql-devel openssl openssl-devel
	yum -y install subversion
	yum -y install libcurl libcurl-devel
	yum -y install libuuid-devel
	yum -y install dos2unix
	yum -y install rpmbuild rpm-build
	yum -y install ruby rubygems ruby-devel
	yum -y install php*
	yum -y install git
	gem sources -a http://ruby.taobao.org/
	gem sources --remove http://rubygems.org/
	gem install fpm
	
	tar -zxvf ./apache-maven-3.2.5-bin.tar.gz
	mv -f apache-maven-3.2.5 /usr/local/
	tar -zxvf ./jdk1.7.0.tgz
	mv -f jdk1.7.0 /usr/local/
	tar -zxvf ./apache-flume-1.6.0-bin.tar.gz
	mv -f apache-flume-1.6.0-bin /usr/local/
	cd /usr/local && mv -f apache-flume-1.6.0-bin apache-flume-1.6.0 && cd -
	
	echo "export JAVA_HOME=/usr/local/jdk1.7.0" >> /etc/profile
	echo "export PATH=\$JAVA_HOME/bin:\$PATH" >> /etc/profile
	echo "export CLASSPATH=.:\$JAVA_HOME/lib/dt.jar:\$JAVA_HOME/lib/tools.jar" >> /etc/profile
	echo "export MAVEN_HOME=/usr/local/apache-maven-3.2.5" >> /etc/profile
	#echo "export PROTOC_HOME=/root/fu/protobuf" >> /etc/profile
	#echo "export ANT_HOME=/root/fu/apache-ant-1.9.6" >> /etc/profile
	echo "export FLUME_HOME=/usr/local/apache-flume-1.6.0" >> /etc/profile
	echo "export FLUME_CONF_DIR=\$FLUME_HOME/conf" >> /etc/profile
	echo "export PATH=\${PATH}:\${MAVEN_HOME}/bin:\${PROTOC_HOME}/bin:\${ANT_HOME}/bin:\${FLUME_HOME}/bin" >> /etc/profile
	#echo "export PATH=\${PATH}:\${MAVEN_HOME}/bin" >> /etc/profile"
	
	
	source /etc/profile
exit 0	
	svn --username=jifu_xu --password=Xjf86479745 checkout svn://192.168.60.105/Cloud/branches/Cloud_Mixed_v1_2_Dev_Branch/portal ./portal
	svn --username=jifu_xu --password=Xjf86479745 checkout svn://192.168.60.105/Cloud/branches/Cloud_Mixed_v1_2_Dev_Branch/appdc_engine/analysis ./analysis
	svn --username=jifu_xu --password=Xjf86479745 checkout svn://192.168.60.105/Cloud/branches/Cloud_Mixed_v1_2_Dev_Branch/appdc_engine/api ./api
	svn --username=jifu_xu --password=Xjf86479745 checkout svn://192.168.60.105/Cloud/branches/Cloud_Mixed_v1_2_Dev_Branch/appdc_engine/backend_api ./backend_api
	svn --username=jifu_xu --password=Xjf86479745 checkout svn://192.168.60.105/Cloud/branches/Cloud_Mixed_v1_2_Dev_Branch/appdc_engine/collector ./collector
	svn --username=jifu_xu --password=Xjf86479745 checkout svn://192.168.60.105/Cloud/branches/Cloud_Mixed_v1_2_Dev_Branch/appdc_engine/index ./index
	svn --username=jifu_xu --password=Xjf86479745 checkout svn://192.168.60.105/Cloud/branches/Cloud_Mixed_v1_2_Dev_Branch/appdc_engine/puppet/upgrade ./upgrade
	svn --username=jifu_xu --password=Xjf86479745 checkout svn://192.168.60.105/Cloud/branches/Cloud_Mixed_v1_2_Dev_Branch/appdc_engine/puppet/makefile ./makefile
	cd ./collector/appdc-collector/deps && make && cd -
	cd ./analysis && make mvn-install && cd -
	cd ./collector && make mvn-install && cd -
	chmod -R +x makefile/*
	mkdir rpm
	echo "1.2.0" > version
fi

if [ $1 == 'version0' ];then
	source /etc/profile
	cat version
	V1=$(cat version | cut -d '.' -f 1)
	V2=$(cat version | cut -d '.' -f 2)
	V3=$(cat version | cut -d '.' -f 3)

	echo ${V1}.${V2}.${V3}
	grep -r --exclude-dir=.svn "${V1}\.${V2}\.${V3}" makefile/* | cut -d ':' -f 1 | xargs sed -i "s/${V1}\.${V2}\.${V3}/1.2.0/g"
	./Makefile rpm all
	
	grep -r --exclude-dir=.svn "1\.2\.0" makefile/* | cut -d ':' -f 1 | xargs sed -i "s/1\.2\.0/${V1}.${V2}.${V3}/g"
fi

if [ $1 == 'version' ];then
	cat version
	V1=`cat version | cut -d '.' -f 1`
	V2=`cat version | cut -d '.' -f 2`
	V3=`cat version | cut -d '.' -f 3`

	V4=$((V3+1))
	echo $V4

	grep -r --exclude-dir=.svn "${V1}\.${V2}\.${V3}" makefile/* | cut -d ':' -f 1 | xargs sed -i "s/${V1}\.${V2}\.${V3}/${V1}.${V2}.${V4}/g"

	echo ${V1}.${V2}.${V4} > version
fi

if [ $1 == 'rpm' ];then
	source /etc/profile
	rm -rf rpm/*.rpm
	#api
	if [ $2 == 'all' ] || [ $2 == 'api' ];then
		cp -rf ./makefile/api/* ./api/
		cd ./api && svn update && make private-rpm && cd -
		mv ./api/appdc-api-server*.rpm ./rpm
	fi
	#backend_api
	if [ $2 == 'all' ] || [ $2 == 'backend-api' ];then
		cp -rf ./makefile/backend_api/* ./backend_api
		cd ./backend_api && svn update && make private-rpm && cd -
		mv ./backend_api/appdc-backend-api*.rpm ./rpm
	fi
	#collector
	if [ $2 == 'all' ] || [ $2 == 'collector' ];then
		cp -rf ./makefile/collector/Makefile ./collector/appdc-collector/src/
		cp -rf ./makefile/collector/private* ./collector/appdc-collector/scripts/
		cd ./collector/appdc-collector/src && svn update && make private-rpm && cd -
		mv ./collector/appdc-collector/rpm/appdc-collector*.rpm ./rpm
	fi
	#hadoop jobs rpm
	if [ $2 == 'all' ] || [ $2 == 'hadoopjobs' ];then
		cp -rf ./makefile/hadoopjobs/* ./analysis
		cd ./analysis && svn update && make 360 && ./create_makefile.sh && cd -
		mv ./analysis/appdc-hadoop-jobs*.rpm ./rpm
	fi
	#index-mgt
	if [ $2 == 'all' ] || [ $2 == 'index-mgt' ];then
		cp -rf ./makefile/index_mgt/private_index_mgt.spec ./index/index_mgt/
		cd ./index/index_mgt && svn update && rpmbuild -bb private_index_mgt.spec && cd -
		mv /root/rpmbuild/RPMS/x86_64/appdc-index-mgt*.rpm ./rpm
	fi
	#indexer
	if [ $2 == 'all' ] || [ $2 == 'indexer' ];then
		cp -rf ./makefile/indexer/* ./collector/appdc-indexer-install
		cd ./collector && svn update && make mvn && cd -
		cd ./collector/appdc-indexer-install && svn update && make private-rpm && cd -
		mv ./collector/appdc-indexer-install/appdc-indexer*.rpm ./rpm
	fi
	#indexer-to-hdfs
	if [ $2 == 'all' ] || [ $2 == 'indexer-to-hdfs' ];then
		cp -rf ./makefile/indexer_to_hdfs/* ./collector/appdc-indexer-to-hdfs
		cd ./collector/appdc-indexer-to-hdfs && svn update && make private-rpm && cd -
		mv ./collector/appdc-indexer-to-hdfs/rpm/appdc-indexer-to-hdfs*.rpm ./rpm
	fi
	#intelligence
	if [ $2 == 'all' ] || [ $2 == 'intelligence' ];then
		cp -rf ./makefile/intelligence_update/* ./analysis/intelligence/intelligence_update
		cd ./analysis/intelligence/intelligence_update && svn update && make private-rpm && cd -
		mv ./analysis/intelligence/intelligence_update/appdc-intelligence*.rpm ./rpm
	fi
	#jobmgr
	if [ $2 == 'all' ] || [ $2 == 'jobmgr' ];then
		cp -rf ./makefile/job_manager/* ./analysis/job_manager
		cd ./analysis/job_manager && svn update && make private-rpm && cd -
		mv ./analysis/job_manager/appdc-jobmgr*.rpm ./rpm
	fi
	#upgrade
	if [ $2 == 'all' ] || [ $2 == 'upgrade' ];then
		cp -rf ./makefile/upgrade/* ./upgrade
		cd ./upgrade && svn update && make private-rpm && cd -
		mv ./upgrade/appdc-package-upgrade*.rpm ./rpm
	fi
	#portal rpm
	if [ $2 == 'all' ] || [ $2 == 'portal' ];then
		cp -rf ./makefile/portal/* ./portal
		cd ./portal && svn update && make private-rpm && cd -
		mv ./portal/appdc-portal*.rpm ./rpm
	fi
fi
